home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / EXTERROR.C < prev    next >
C/C++ Source or Header  |  1993-01-28  |  2KB  |  92 lines

  1. /*****************************************************************************
  2.  * EXTERROR.C - Extended error message handling.
  3.  ****************************************************************************/
  4.  
  5. #include "gemfintl.h"
  6. #include "exterror.h"
  7. #include <string.h>
  8.  
  9. #define MAX_EXT_TABLES    8
  10.  
  11. static _Err_tab GFAR internal_errors[] = {
  12.     gfErr_no_memory,        "Out of memory",
  13.     gfErr_vdi_handle,        "Out of VDI handles",
  14.     gfErr_parameter_range,    "Parameter value out of range",
  15.     gfErr_parameter_null,    "Invalid NULL pointer parameter",
  16.     gfErr_resource_in_use,    "Required internal resource in use",
  17.     gfErr_wrong_type,        "Specified object is the wrong type",
  18.     gfErr_option_invalid,    "Invalid option requested",
  19.     gfErr_action_invalid,    "Invalid action requested",
  20.     gfErr_object_too_small, "Specified object is too small",
  21.     gfErr_object_too_big,    "Specified object is too big",
  22.     0,                        NULL
  23. };
  24.  
  25. static _Err_tab *extmsg_tables[MAX_EXT_TABLES] = {internal_errors};
  26. static char     nullstr[] = "";
  27.  
  28. /*----------------------------------------------------------------------------
  29.  * exterrset - Install or remove an application-specific error msg table.
  30.  *--------------------------------------------------------------------------*/
  31.  
  32. int exterrset(ptab, install)
  33.     _Err_tab    *ptab;
  34.     int       install;
  35. {
  36.     register short        tabidx;
  37.     register _Err_tab **pptab = extmsg_tables;
  38.  
  39.     for (tabidx = 0; tabidx < MAX_EXT_TABLES; ++tabidx, ++pptab) {
  40.         if (install) {
  41.             if (*pptab == NULL) {
  42.                 *pptab = ptab;
  43.                 return E_OK;
  44.             }
  45.         } else {
  46.             if (*pptab == ptab) {
  47.                 *pptab = NULL;
  48.                 return E_OK;
  49.             }
  50.         }
  51.     }
  52.  
  53.     return ERROR;
  54. }
  55.  
  56. /*----------------------------------------------------------------------------
  57.  * exterror - like strerror(), but looks for application-specific msg first.
  58.  *--------------------------------------------------------------------------*/
  59.  
  60. char *exterror(err)
  61.     register int err;
  62. {
  63.     register short        tabidx;
  64.     register _Err_tab *ptab;
  65.     register char      *themsg;
  66.  
  67.     for (tabidx = 0; tabidx < MAX_EXT_TABLES; ++tabidx) {
  68.         for (ptab = extmsg_tables[tabidx]; ptab && ptab->code; ++ptab) {
  69.             if (ptab->code == err) {
  70.                 themsg = ptab->msg;
  71.                 goto RETURN_IT;
  72.             }
  73.         }
  74.     }
  75.  
  76.     if (err == 0) {
  77.         themsg = nullstr;
  78.     } else {
  79.         themsg = strerror(err);
  80.     }
  81.  
  82. RETURN_IT:
  83.  
  84.     if (themsg == NULL) {
  85.         themsg = nullstr;
  86.     }
  87.  
  88.     return themsg;
  89. }
  90.  
  91.  
  92.